/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - core/memory
// Copyright( c) 2013.  All Rights Reserved
//
// File:		AEMemoryManager.inl
// Author:		Gianluca Belardelli
// Date:		31/12/2013
//
/////////////////////////////////////////////////////////////////////////
#ifndef _AEMEMORYMANAGER_INL_
#define _AEMEMORYMANAGER_INL_

AE_FORCEINLINE AEMemoryAllocator &AEMemoryManager::GetTempAllocator( void )
{
	return *m_lpTemp;
}

AE_FORCEINLINE void AEMemoryManager::SetTempAllocator( AEMemoryAllocator *lpAllocator )
{
	m_lpTemp = lpAllocator;
}

AE_FORCEINLINE AEMemoryAllocator &AEMemoryManager::GetHeapAllocator( void )
{
	return *m_lpHeap;
}

AE_FORCEINLINE void AEMemoryManager::SetHeapAllocator( AEMemoryAllocator *lpAllocator )
{
	m_lpHeap = lpAllocator;
}

AE_FORCEINLINE AEMemoryAllocator &AEMemoryManager::GetDebugAllocator( void )
{
	return *m_lpDebug;
}

AE_FORCEINLINE void AEMemoryManager::SetDebugAllocator( AEMemoryAllocator *lpAllocator )
{
	m_lpDebug = lpAllocator;
}
/*
AE_FORCEINLINE Stack &AEMemoryManager::GetStack( void )
{
	return m_Stack;
}
*/
inline AEMemoryManager & AE_CALL AEMemoryManager::GetInstance ( void )
{
	return *AE_THREAD_LOCAL_GET( m_lpInstance );
}
inline AEMemoryManager * AE_CALL AEMemoryManager::GetInstancePtr( void )
{
	return AE_THREAD_LOCAL_GET( m_lpInstance );
}

template <typename T>
AE_FORCEINLINE T* AEAllocateStack( AEINT32 nSize, const char *lpDescriptor )
{
	AEMemoryManager &refMemMgr = AEMemoryManager::GetInstance();
	return static_cast<T*>(refMemMgr.GetStack().BlockAlloc(AE_NEXT_MULTIPLE_OF(128,nSize*AESizeOfTypeOrVoid<T>::val)));
}

#endif // _AEMEMORYMANAGER_INL_
